package com.example.administrator.hqq.adapter.group;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.group.GetGroupSettingsBean;
import com.example.administrator.hqq.utils.transform.GlideCircleTransform;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/11/18 17:52
 * @remark:
 */
public class KickGroupListAdapter extends BaseAdapter {
    private Context context;
    private List<GetGroupSettingsBean.DataBean.MemberBean> lists;
    private String group_owner = "";

    public void setGroup_owner(String group_owner) {
        this.group_owner = group_owner;
    }

    public KickGroupListAdapter(Context context, List<GetGroupSettingsBean.DataBean.MemberBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.kick_group_list_item, viewGroup, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (group_owner.equals(lists.get(i).getId())) {
            viewHolder.deleteMemberImage.setVisibility(View.GONE);
        }
        Glide.with(context).load(lists.get(i).getUrl()).transform(new CenterCrop(context), new GlideCircleTransform(context)).into(viewHolder.image);
        viewHolder.name.setText(lists.get(i).getName());
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.image)
        ImageView image;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.delete_member_image)
        ImageView deleteMemberImage;
        @BindView(R.id.delete_member)
        AutoRelativeLayout deleteMember;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
